﻿<%@ Page Title="" Language="C#" MasterPageFile="~/WebSite.Master" AutoEventWireup="true"
    CodeBehind="PersonEmpZGZSList.aspx.cs" Inherits="RN.ERP.Web.Person.PersonEmpZGZSList" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div>
        <label>
            资格证书大类
        </label>
        <asp:DropDownList ID="ddlParent" runat="server">
        </asp:DropDownList>
        <label>
            子项
        </label>
        <asp:DropDownList ID="ddlZGZS" runat="server">
        </asp:DropDownList>
        <input id="btnSearch" type="button" value="查询" />
        <input id="btnAdd" type="button" value="新增" />
        <input id="btnModify" type="button" value="修改" />
    </div>
    <br />
    <div id="divDetail_ZGZS" style="visibility: hidden">
        <label>
            编号</label>
        <input id="txtZGZSCode" type="text" />
        <label>
            资格证书名称</label>
        <input id="txtZGZSName" type="text" />
        <div id="divNew" style="visibility: hidden">
            <label>
                新编号</label>
            <input id="txtNewCode" type="text" />
            <label>
                新资格证书名称</label>
            <input id="txtNewName" type="text" />
        </div>
        <input id="hdnParentSID" type="hidden" />
        <input id="hdnRootCode" type="hidden" />
        <input id="hdnSortValue" type="hidden" />
        <br />
        <input id="btnSave" type="button" value="保存" />
    </div>
    <div runat="server">
        <script type="text/javascript">
            $(function () {
                $("#hdnRootCode").val("ZGZSLC");
                var ZGZSCode = $("#<%=ddlZGZS.ClientID %>").val();
                var ZGZSName = $("#<%=ddlZGZS.ClientID %> option:selected").text();
                var ParentSID = $("#<%=ddlParent.ClientID %>").val();

                //参数
                var parentsid = $("#hdnParentSID").val();
                var newcode = $("#txtNewCode").val();
                var newname = $("#txtNewName").val();
                var rootcode = $("#hdnRootCode").val();
                var sortvalue = $("#hdnSortValue").val();
                var zgzscode = $("#txtZGZSCode").val();
                var zgzsname = $("#txtZGZSName").val();

                LoadZGZS("ZGZSLC", "0", 1);

                $("#<%=ddlParent.ClientID %>").change(function () {
                    $("#hdnParentSID").val(ParentSID);
                    LoadZGZS("ZGZSLC", ParentSID, 2);
                });

                //查询
                $("#btnSearch").click(function () {
                    if (ZGZSCode < 0) {
                        alert("请选择一项资格证书！");
                        return false;
                    }
                    else {
                        $("#divDetail_ZGZS").css("visibility", "visible");
                        $("#txtZGZSCode").val(ZGZSCode);
                        $("#txtZGZSName").val(ZGZSName);
                        $("#hdnParentSID").val(ParentSID);
                        $("#txtZGZSCode").attr("disabled", true);
                        $("#txtZGZSName").attr("disabled", true);
                        $("#btnSave").css("visibility", "hidden");
                        $("#divNew").css("visibility", "hidden");
                        $("#btnSave").css("visibility", "hidden");
                    }
                });

                //新增
                $("#btnAdd").click(function () {
                    $("#divDetail_ZGZS").css("visibility", "visible");
                    $("#hdnParentSID").val(ParentSID);
                    $("#txtZGZSCode").attr("disabled", false);
                    $("#txtZGZSName").attr("disabled", false);
                    $("#divNew").css("visibility", "hidden");
                    $("#btnSave").css("visibility", "visible");
                });

                //修改
                $("#btnModify").click(function () {
                    if (ZGZSCode < 0) {
                        alert("请选择一项资格证书！");
                        return false;
                    }
                    else {
                        $("#divDetail_ZGZS").css("visibility", "visible");
                        $("#hdnParentSID").val(ParentSID);
                        $("#txtZGZSCode").attr("disabled", true);
                        $("#txtZGZSName").attr("disabled", true);
                        $("#divNew").css("visibility", "visible");
                        $("#btnSave").css("visibility", "visible");
                    }
                });

                //保存
                $("#btnSave").click(function () {
                    SaveZGZS(zgzscode, zgzsname, newcode, newname, parentsid, rootcode, sortvalue);
                });
            });

            //加载资格证书列表，1表示加载大类，2表示加载子项
            function LoadZGZS(rootCode, parentSID, action) {
                $.ajax({
                    url: "../Handlers/PsnZGZSHandler.ashx",
                    type: "Post",
                    contentType: "application/json",
                    type: "POST",
                    data: { "action": "GetList", "RootCode": rootCode, "ParentSID": parentSID },
                    datatype: "json",
                    success: function (data) {
                        switch (action) {
                            case 1:
                                $("#ddlParent option").remove();
                                $("#ddlParent").append("<option  value='-1'>请选择</option>");
                                break;
                            case 2:
                                $("#ddlZGZS option").remove();
                                $("#ddlZGZS").append("<option  value='-1'>请选择</option>");
                                break;
                            default:
                                $("#ddlParent").append("<option  value='-1'>请选择</option>");
                                break;
                        }
                        var result = eval(data);
                        $(result).each(function (key) {
                            var text = result[key].Title;
                            var value = result[key].Code;
                            switch (action) {
                                case 1:
                                    $("#ddlParent").append("<option  value='" + value + "'>" + text + "</option>");
                                    break;
                                case 2:
                                    $("#ddlZGZS").append("<option  value='" + value + "'>" + text + "</option>");
                                    break;
                                default:
                                    $("#ddlParent").append("<option  value='" + value + "'>" + text + "</option>");
                                    break;
                            }

                        });
                    },
                    error: function (data) {
                        alert("获取下拉列表失败！");
                    }
                }
            );
            }

            //提交资格证书信息
            function SaveZGZS(zgzsCode, zgzsName, zgzsNewCode, zgzsNewName, parentSID, rootCode, sortValue) {
                $.ajax({
                    data: { "action": "Update", "zgzsCode": zgzsCode, "zgzsName": zgzsName, "zgzsNewCode": zgzsNewCode, "zgzsNewName": zgzsNewName, "parentSID": parentSID, "rootCode": rootCode, "sortValue": sortValue },
                    type: "POST",
                    url: "../Handlers/PsnZGZSHandler.ashx",
                    datetype: "json",
                    success: function (data) {
                        alert(data);
                        $("#divDetail_ZGZS").css("visibility", "hidden");
                        $("#divNew").css("visibility", "hidden");
                    },
                    error: function (data) {
                        alert(data);
                    }
                });
            }
        </script>
    </div>
</asp:Content>
